const app = getApp()

import axios from '../../utils/axios'

Page({

  data: {
    brandId: '',
    brandImage: '',
    commodityList: [],
  },

  onLoad: function (options) {
    this.setData({
      brandId: options.brandId,
      brandImage: app.globalData.brandImage
    })

    if (app.globalData.brandImage == "" || app.globalData.brandImage == null) {
      this.selectActivityFeature()
    }

    this.selectFeatureGoodsList()

  },

  onShow: function () {

  },

  // 查询专题商品列表
  selectFeatureGoodsList: function () {
    axios("/groupon/featureGoodsList", {
      feature_id: this.data.brandId
    }).then(res => {
      console.log(res)
      if (res.data.resultcode == 1) {
        for (let i = 0; i < res.data.result.length; i++) {
          res.data.result[i]['name'] = res.data.result[i].title
        }
        this.setData({
          commodityList: app.disposeList(res.data.result)
        })
      }
    })
  },

  // 查询活动专题列表
  selectActivityFeature: function () {
    axios("/groupon/feature", {
      type: 2
    }).then(res => {
      if (res.data.resultcode == 1) {
        this.setData({
          brandImage: res.data.result[0].image
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})